package com.alveole.dao;

import org.apache.openjpa.persistence.OpenJPAEntityManager;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
import org.apache.openjpa.persistence.OpenJPAPersistence;

public class Dao {
	
	
	private static Dao dao;
	private OpenJPAEntityManager em;
	
	private OpenJPAEntityManager getEntityManager()
	{
		if (em==null)
		{
			OpenJPAEntityManagerFactory emf = OpenJPAPersistence.getEntityManagerFactory();
			em=emf.createEntityManager();
		}
		return em;
	}
	private static Dao getDao()
	{
		if (dao==null) dao=new Dao();
		return dao;
	}
	public static OpenJPAEntityManager em()
	{
		return getDao().getEntityManager();
	}
}
